package com.webserver.core;

import com.webserver.http.HttpRequest;
import com.webserver.http.HttpResponse;

import java.io.File;

/**
 * 用于处理请求
 */
public class DispatcherServlet {
    public void service(HttpRequest httpRequest, HttpResponse response){
        String patch=httpRequest.getUri();
        File file=new File("./webapps"+ patch);
        if(file.exists()&&file.isFile() ){
            //正确情况
            response.setEntity(file);
        }else {
            response.setStatusCode(404);
            response.setStatusReason("NotFound");
            response.setEntity(new File("./webapps/root/404.html"));
        }
    }
}
